<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>会员中心</title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
		<link rel="stylesheet" href="../css/mint-ui.css" />
		<link rel="stylesheet" href="../css/main.css" />
	</head>
	<body>
		<div id="app">
			<img src="../images/logo.jpg" width="100%"/>
			<div class="personalINfo">
				<img v-if="userPic != ''" :src="userPic" class="touxiang" />
				<img v-else src="../images/picture.jpg" class="touxiang" />
				<p>{{babyName}}</p>
				<strong v-if="level == 1">普通会员</strong>
				<strong v-if="level == 2">自由会员</strong>
				<strong v-if="level == 3">月度会员</strong>
				<strong v-if="level == 4">季度会员</strong>
				<strong v-if="level == 5">半年会员</strong>
				<strong v-if="level == 6">年度会员</strong>
				<strong v-if="level == 7">至尊会员</strong>
			</div>
			<div class="babyShow">
				<img v-if="sex==1" src="../images/boy.jpg" />
				<img v-if="sex==0" src="../images/girl.jpg" />
				<span>{{babyName}}</span>
				<span v-if="sex==1">男</span>
				<span v-if="sex==0">女</span>
				<span>{{age}}</span>
			</div>
			<div class="payMoney">
				您当前余额：{{money}}元<br />
				<span v-if="noPay == true && level != 2">您暂未充值会员</span>
				<span v-if="noPay == false && level != 2">您有{{endMoney}}元将于{{endTime}}到期</span>
				<span v-if="noPay == true && level == 2">自由会员凭次消费</span>
				<span @click="goPay" class="btnSelf">去充值</span>
			</div>
			<div class="payMoney">
				您当前积分：{{score}}分<br />将于{{endTimes}}年12月31日到期
				<span @click="goChange" class="btnSelf">去兑换</span>
			</div>
			<br />
		</div>
	</body>
	<script type="text/javascript" src="../js/vue.js" ></script>
	<script type="text/javascript" src="../js/mint-ui.js" ></script>
	<script type="text/javascript" src="../js/rem.js" ></script>
	<script type="text/javascript" src="../js/axios.min.js" ></script>
	<script>
		var openId=location.search.substring(8);
		localStorage.setItem("openId",openId);//缓存openId
		new Vue({
			el:"#app",
			data:{
				babyName:"",//宝宝姓名
				sex:"",//宝宝性别
				age:"",//宝宝年龄
				userName:"",//微信昵称
				level:"1",//会员等级
				userPic:"",//用户头像
				money:"",//当前余额
				endMoney:"",//到期金额
				endTime:"",//余额到期日期
				score:"",//积分
				endTimes:"", //积分到期时间
				noPay:true,//是否充值过
//				userId:""
			},
			created(){
//				this.openId=localStorage.getItem("openId");
				this.endTimes=new Date().getFullYear();
				axios.post('http://106.13.55.49/api/jdUser/userCenter?openid='+openId)
				.then((data) => {
						console.log(data);
						let datas=data.data.data;
						if(data.data.status == 200){
							this.userPic=datas.user.avatar;
							this.userName=datas.user.username;
							this.babyName=datas.baby.babyname;
							this.level=datas.user.userLevelId;
							this.sex=datas.baby.six;
							this.money=datas.useraccount.balance;
							this.score=datas.useraccount.credits;
//							localStorage.setItem("score",this.score);//缓存剩余积分
							let newY,newM;
							let year=datas.baby.birthday.substring(0,4);
							let month=datas.baby.birthday.substring(5,7);
							let dd=new Date();
							let year2=dd.getFullYear()-year;
							let months=dd.getMonth()+1-month;
							if(months<0){//如果月份小的话做处理
								newM=months+12;
								newY=year2-1;
							}else{
								newY=year2;
								newM=months;
							}
							this.age=newY+"岁"+newM+"个月";
							if(datas.useraccount.expireMsg != "" || datas.useraccount.expireMsg != undefined){
								this.endMoney=datas.useraccount.expireMsg.money;
								this.endTime=datas.useraccount.expireMsg.expireTime.substring(0,10);
								this.noPay=true;
							}else{
								this.endMoney="";
								this.endTime="";
							}
						}else{
							this.$toast(data.data.message);return;
						}
				})
			},
			methods:{
				//去充值
				goPay:function(){
					location.href="pay.html";
				},
				//去兑换积分
				goChange:function(){
					location.href="forChange.html";
				}
				
			}
			
		})
	</script>
</html>
